//
//  HRZOrderService.m
//  EMarket
//
//  Created by 石头 on 2018/8/28.
//  Copyright © 2018 好日子. All rights reserved.
//

#import "HRZOrderService.h"
// Controllers

// Models
#import "HRZIssuedOrderModel.h"
#import "HRZOrderPayModel.h"
#import "HRZOrderStatusModel.h"
#import "HRZSearchOrderDetailModel.h"

#import "HRZOrderModel.h"
// Views

// Vendors

// Categories

// Others


@interface HRZOrderService ()

@end

@implementation HRZOrderService

+ (void)createIssuedOrderModelWith:(HRZIssuedOrderModel *)model
                           success:(void (^)(NSString *))success
                           failure:(void (^)(NSString *))failure {
    NSMutableDictionary *params = [model mj_keyValues];
    HRZAPIRequest *request = [[HRZAPIRequest alloc] initWithAPIRequestType:kAPIRequestType_Get withSubPath:kCreateOrderUrl];
    request.params = params;
    [HRZAPIClient execute:request];
    
    request.ServerSuce = ^(NSDictionary *sucObj) {
        success(@"");
    };
    
    request.ServerFail = ^(NSString *error) {
        failure(error);
    };
}

+ (void)creatOrderByOrderModel:(HRZIssuedOrderModel *)model
                       success:(void (^)(NSString *))success
                       failure:(void (^)(NSString *))failure {
    NSMutableDictionary *params = [model mj_keyValues];
    HRZAPIRequest *request = [[HRZAPIRequest alloc] initWithAPIRequestType:kAPIRequestType_Post withSubPath:kCreateOrderUrl];
    request.params = params;
    [HRZAPIClient execute:request];
    
    request.ServerSuce = ^(NSDictionary *sucObj) {
        success(@"");
    };
    
    request.ServerFail = ^(NSString *error) {
        failure(error);
    };
}

+ (void)createOrderPayModel:(HRZOrderPayModel *)model
                    success:(void (^)(NSString *))success
                    failure:(void (^)(NSString *))failure {
    NSMutableDictionary *params = [model mj_keyValues];
    HRZAPIRequest *request = [[HRZAPIRequest alloc] initWithAPIRequestType:kAPIRequestType_Post withSubPath:kCreateOrderPayTypeUrl];
    request.params = params;
    [HRZAPIClient execute:request];
    
    request.ServerSuce = ^(NSDictionary *sucObj) {
        success(@"");
    };
    
    request.ServerFail = ^(NSString *error) {
        failure(error);
    };
}

+ (void)searchOrderClassifyByOrderStatus:(HRZOrderStatusModel *)model
                                 success:(void (^)(NSArray<HRZOrderModel *> *))success
                                 failure:(void (^)(NSString *))failure {
    
    NSMutableDictionary *params = [model mj_keyValues];
    HRZAPIRequest *request = [[HRZAPIRequest alloc] initWithAPIRequestType:kAPIRequestType_Get withSubPath:kGetOrderUrl];
    request.params = params;
    [HRZAPIClient execute:request];
    
    request.ServerSuce = ^(NSDictionary *sucObj) {
        
        NSArray *array = [HRZOrderModel mj_objectArrayWithKeyValuesArray:sucObj];
        
        success(array);
    };
    
    request.ServerFail = ^(NSString *error) {
        failure(error);
    };
}

+ (void)searchOrderDetailByModel:(HRZSearchOrderDetailModel *)model
                         success:(void (^)(HRZOrderModel *))success
                         failure:(void (^)(NSString *))failure {
    
    NSMutableDictionary *params = [model mj_keyValues];
    HRZAPIRequest *request = [[HRZAPIRequest alloc] initWithAPIRequestType:kAPIRequestType_Get withSubPath:kGetOrderDetailUrl];
    request.params = params;
    [HRZAPIClient execute:request];
    
    request.ServerSuce = ^(NSDictionary *sucObj) {
        HRZOrderModel *model = [HRZOrderModel mj_objectWithKeyValues:sucObj];
        success(model);
    };
    
    request.ServerFail = ^(NSString *error) {
        failure(error);
    };
}

@end
